<template>
<view class="container">
 <block v-if="!List">  
    <view class="none">没有相关订单</view>
 </block>
 <block v-else> 
    <view class="cartContainer" v-for="(list, index) in List" :key="index">
      <view class="cartbannerName"> 
        <text class="font1">客户名：</text>
        <text class="marginleft" :style="'color:' + setting.platformSetting.defaultColor">{{list.buyerName}}</text>
      </view>
      <view class="cartShopName"> 
        <text class="font1">{{list.addTime}}</text>
        <text class :style="'color:' + setting.platformSetting.defaultColor">{{list.orderStatusStr }}</text>
      </view>

      <view class="cartItems">
        <view class="itemCheckbox">
          <image mode="aspectFill" :src="(list.itemIcon?list.itemIcon:'https://image1.sansancloud.com/yunjishi/2018_12/5/11/1/31_158.jpg') + '?x-oss-process=style/preview'"></image>
        </view>
        <view class="item_infomation">
          <view class="item_infomation_name font1">{{list.itemName}}</view>

          <view class="item_infomation_name2" v-if="!!list.measureCartesianId">{{list.measures}}</view>
          <view class="item_infomation_nums"> 
            <text class="flexCenter">x {{list.itemCount}}</text>
          </view>
          <view class="item_infomation_money">
            <view>单价:￥<text class="fontPrice">{{list.itemPrice}}</text></view>
            <text>订单号:{{list.orderNo}}</text>
          </view>
        </view>
      </view>

      <view class="butn_container">
          <!-- <text>订单金额￥{{list.supplyPrice }}</text> -->
          <text v-if="list.getMendianSelfStorage==1" :style="'color:' + setting.platformSetting.defaultColor">（预估收入￥{{list.supplyPrice}}）</text>
          <text v-else :style="'color:' + setting.platformSetting.defaultColor">（预估收入￥{{list.distributeProfitResult}}）</text>
      </view>
      <!-- 订单类型不同，按钮不一样 -->
      <view v-if="list.easyStatus == 2" class="butn_container2">
          <text :data-order="list" @tap="editOrder">编辑订单</text>
          <text :data-order="list" @tap="pay">立即付款</text>
          <text :data-orderNo="list.orderNo" @tap="delectOrder">删除订单</text>
      </view>
      <view v-if="list.easyStatus == 3" class="butn_container2">
        <text :data-orderNo="list.orderNo" @tap="cancelOrder">取消订单</text>
      </view>
      <view v-if="list.easyStatus == 4" class="butn_container2">
          <text :data-orderNo="list.orderNo" @tap="arriverOrder">确认收货</text>
      </view>

      <!-- <view wx:if='{{list.easyStatus == 5}}' class='butn_container2'>
          <text data-orderNo='{{list.orderNo}}' bindtap='pingjiaOrder'>评价</text>
      </view> -->

    </view>
 </block>
  
</view>
</template>

<script>

export default {
  data() {
    return {
      List: [],

      /**
       * 生命周期函数--监听页面加载
       */
      options: {},
      listPage: {
        page: 1,
        pageSize: 0,
        totalSize: 0,
        curpage: 1
      },
      setting: ""
    };
  },

  components: {},
  props: {},
  onLoad: function (options) {
    this.options = options;
    this.get_fx_usersFun(options);
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {
    this.setData({
      setting: getApp().globalData.setting
    });
  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {},

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {},

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {},

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {
    this.favouriteList = [];
    this.listPage.page = 1;
    this.get_fx_usersFun(this.options, 1);
    wx.stopPullDownRefresh();
  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {
    var that = this;

    if (that.listPage.totalSize > that.listPage.curPage * that.listPage.pageSize) {
      that.listPage.page++;
      this.get_fx_usersFun(this.options);
    }
  },
  methods: {
    distributeProfit: function (result) {
      for (let i = 0; i < result.length; i++) {
        result[i].distributeProfitResult = (result[i].distributeProfit * (result[i].itemCount - result[i].backCount) * getApp().globalData.setting.platformSetting.mendianDistributeProfit / 100).toFixed(2);
      }

      return result;
    },
    get_fx_usersFun: function (options, fresh) {
      let getParam = {};
      getParam.page = this.listPage.page;
      var customIndex = getApp().globalData.AddClientUrl("/get_mendian_order_items_admin_mendian_json.html", getParam, 'post');
      var that = this; // wx.showLoading({
      //   title: 'loading'
      // })

      getApp().globalData.showToastLoading('loading', true);
      wx.request({
        url: customIndex.url,
        data: customIndex.params,
        header: getApp().globalData.headerPost,
        method: 'POST',
        success: function (res) {
          console.log(res.data);

          if (res.data.errcode == '0') {
            that.listPage.pageSize = res.data.relateObj.pageSize;
            that.listPage.curPage = res.data.relateObj.curPage;
            that.listPage.totalSize = res.data.relateObj.totalSize;
            let result = that.distributeProfit(res.data.relateObj.result);
            let List = that.List;

            if (fresh) {
              List = [];
            }

            if (!result || result.length == 0) {
              that.setData({
                List: null
              });
            } else {
              List = List.concat(result);
              that.setData({
                List: List
              });
            }
          }

          wx.hideLoading();
        },
        fail: function (res) {
          wx.hideLoading();
          getApp().globalData.loadFail();
        }
      });
    },
    setData: function (obj) {
      let that = this;
      let keys = [];
      let val, data;
      Object.keys(obj).forEach(function (key) {
        keys = key.split('.');
        val = obj[key];
        data = that.$data;
        keys.forEach(function (key2, index) {
          if (index + 1 == keys.length) {
            that.$set(data, key2, val);
          } else {
            if (!data[key2]) {
              that.$set(data, key2, {});
            }
          }

          data = data[key2];
        });
      });
    }
  }
};
</script>
<style scoped>
@import "./index.css";
</style>